package com.czxy.service;

import com.czxy.dao.StudentMapper;
import com.czxy.domain.Student;
import com.czxy.utils.MybatisUtil;

import java.util.List;

public class StudentService {

    public List<Student> findAll(){
        StudentMapper mapper = MybatisUtil.getMapper(StudentMapper.class);
        List<Student> list = mapper.findAll();
        MybatisUtil.close();
        return list;
    }




    public List<Student> findSname(String studentname){
        StudentMapper mapper = MybatisUtil.getMapper(StudentMapper.class);
        List<Student> list = mapper.findSname("%" + studentname + "%");
        MybatisUtil.close();
        return list;
    }

    public  boolean add(Student student){

        StudentMapper mapper = MybatisUtil.getMapper(StudentMapper.class);
        List<Student> list = mapper.findLname(student);

        if (list.size()!=0){

            MybatisUtil.close();
            return false;
        }else {

            mapper.insert(student);
            MybatisUtil.commitAndclose();
            return true;
        }
    }

    public  void  delete(String sid){
        StudentMapper mapper = MybatisUtil.getMapper(StudentMapper.class);
        mapper.delete(sid);
        MybatisUtil.commitAndclose();
    }

    public Student findSId(String sid){
        StudentMapper mapper = MybatisUtil.getMapper(StudentMapper.class);
        Student student = mapper.findSId(sid);
        MybatisUtil.close();
        return student;
    }

    public boolean update(Student student){
        StudentMapper mapper = MybatisUtil.getMapper(StudentMapper.class);

        List<Student> list = mapper.findRname(student);

        if (list.size()!=0){

            MybatisUtil.close();
            return false;
        }else{
           mapper.update(student);
           MybatisUtil.commitAndclose();
           return  true;

        }

    }

    public List<Student> findGId(String sid){

        StudentMapper mapper = MybatisUtil.getMapper(StudentMapper.class);
        mapper.findGId(sid);
        MybatisUtil.close();
        return null;
    }




































}
